
package managedbean.Product;

import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.stateless.ProductBeanLocal;

@ManagedBean(name="addProductManagerBean")
@ViewScoped
public class AddProductManagerBean implements Serializable {

    @EJB
    private ProductBeanLocal productBeanLocal;
    private String productType;
    private double productPrice;
    private boolean success;
    private String statusMessage;
    
    public AddProductManagerBean() {
    }

    public double getProductPrice() {
        return productPrice;
    }

    public void setProductPrice(double productPrice) {
        this.productPrice = productPrice;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
    
    public void saveNewProduct(ActionEvent event) 
    { 
        try {
            productBeanLocal.createProduct(productType, productPrice);
            statusMessage = "New Product Saved Successfully";

            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Add New Discount Result: " + statusMessage, ""));
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
}
